package fr.mywiki.business.versioning;

import fr.mywiki.model.ejbAdapter.Value;

/**
 * This class represents a set of versions in the database. It can contain a set
 * of versions zipped together or a single version.
 * 
 * @author tlombard
 */
public class MultiversionLite extends Value {
	private static final long serialVersionUID = 1L;

	public static final String JNDI_NAME = "MyWiki/Multiversion";

	/** The default object type */
	public static final String TYPE_ENT = "multiversion";

	/* The fields */
	public static final String FIELD_COUNT = "count";
	public static final String FIELD_PROPERTY = "field";
	public static final String FIELD_CONTENT = "content";

	/** Identifier of the object */
	private Long id;

	/** The identifier of the property this objects archives */
	private Long property;
	
	/** The content of the file */
	private byte[] content;

	/** Number of versions contained in that file. */
	private Integer count;

	public String getTypeEnt() {
		return TYPE_ENT;
	}
	
	public MultiversionLite() {
	}
	
	public MultiversionLite(Long id, Long property, Integer count, byte[] content) {
		this.id = id;
		this.property = property;
		this.count = count;
		this.content = content;
	}

	public Object get(String attName) {
		if (FIELD_COUNT.equals(attName))
			return getCount();
		if (FIELD_CONTENT.equals(attName))
			return getContent();
		if (FIELD_PROPERTY.equals(attName))
			return getProperty();
		return null;
	}

	public void set(String attName, Object value) {
		if (FIELD_COUNT.equals(attName))
			setCount((Integer) value);
		else if (FIELD_CONTENT.equals(attName))
			setContent((byte[]) value);
		else if(FIELD_PROPERTY.equals(attName))
			setProperty((Long) value);
	}

	public byte[] getContent() {
		return content;
	}

	public void setContent(byte[] content) {
		this.content = content;
	}

	public Integer getCount() {
		return count;
	}

	public void setCount(Integer count) {
		this.count = count;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getProperty() {
		return property;
	}

	public void setProperty(Long property) {
		this.property = property;
	}
}
